home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / misc / emu / Electrostatic.lha / Electrostatic / hidden / Atari2600.i < prev    next >
Text File  |  1999-10-05  |  3KB  |  214 lines

  1. ; File: Atari2600.i
  2. ; Author: Neil Cafferkey
  3. ; ======================
  4. ;
  5. ; $VER: Atari2600.i 2.1 (25.8.99)
  6. ;
  7.  
  8.     ifnd    atari2600_i
  9. atari2600_i    set    1
  10.  
  11.  
  12.     include    "MOS6507.i"
  13.     include    "Stella.i"
  14.     include    "Riot.i"
  15.  
  16.     include    "asm_support.i"
  17.  
  18.     include    "offsets.i"
  19.  
  20.  
  21.  
  22. ; Macro: START_UP
  23. ; ===============
  24. ;
  25.  
  26.     macro    START_UP
  27.  
  28.     ; Get pointer to exec.library
  29.  
  30.     move.l    4,a6
  31.  
  32.     ; Find the program's process structure
  33.  
  34.     movea.l    #0,a1
  35.     CALLSYS    FindTask
  36.     movea.l    d0,a4
  37.  
  38.     ; Check if the program was started from the Workbench or the CLI
  39.  
  40.     clr.l    wb_msg
  41.     tst.l    (pr_CLI,a4)
  42.     bne    cli$
  43.  
  44. wait_again$:
  45.  
  46.     lea.l    (pr_MsgPort,a4),a0
  47.     CALLSYS    WaitPort
  48.     lea.l    (pr_MsgPort,a4),a0
  49.     CALLSYS    GetMsg
  50.     movea.l    d0,wb_msg
  51.     beq    wait_again$
  52.  
  53.     move.l    d0,extra_tags+4
  54.  
  55. cli$:
  56.  
  57.     ; Open atari2600.library V2+
  58.  
  59.     lea    atari2600Name,a1
  60.     moveq    #2,d0
  61.     CALLSYS    OpenLibrary
  62.  
  63.     ; Store library base. Exit if library couldn't be opened.
  64.  
  65.     move.l    d0,Atari2600Base
  66.     bne    \@opened$
  67.     moveq    #20,d2
  68.     bra    exit
  69.  
  70. \@opened$:
  71.  
  72.     ; Open a new simulated Atari 2600 environment
  73.  
  74.     movea.l    Atari2600Base,a6
  75.  
  76.     move.l    sp,d0
  77.     movea.l    #data,a1
  78.     movea.l    #env_tags,a0
  79.     CALLSYS    A2600_OpenAtari2600
  80.  
  81.     ; Store environment. Exit if environment couldn't be created.
  82.  
  83.     move.l    d0,environment
  84.     movea.l    d0,ENV
  85.     bne    \@env_created$
  86.  
  87.     moveq    #20,d2
  88.     bra    exit
  89.  
  90. \@env_created$:
  91.  
  92.     ; Move ROM image into Atari 2600's address space
  93.  
  94.     movea.l    Atari2600Base,a6
  95.     lea    rom,a0
  96.     lea    data+$1000,a1
  97.     move.l    #$1000,d0
  98.     CALLSYS    A2600_InstallROM
  99.  
  100.     ; Clear all emulation registers
  101.  
  102.     moveq    #0,A
  103.     moveq    #0,X
  104.     moveq    #0,Y
  105.     moveq    #0,P
  106.     moveq    #0,D_FLAG
  107.     move.l    #$ff,S
  108.  
  109.     movea.l    #0,CLOCK
  110.  
  111.     endm
  112.  
  113.  
  114. ; Macro: EXIT
  115. ; ===========
  116. ;
  117.  
  118.     macro    EXIT
  119.  
  120.     ; Close Atari 2600 environment
  121.  
  122.     move.l    environment,d0
  123.     movea.l    d0,a1
  124.     beq    \@env_not_opened$
  125.     movea.l    Atari2600Base,a6
  126.     CALLSYS    A2600_CloseAtari2600
  127.  
  128. \@env_not_opened$:
  129.  
  130.     ; Close Atari 2600 library
  131.  
  132.     move.l    Atari2600Base,d0
  133.     movea.l    d0,a1
  134.     beq    \@lib_not_opened$
  135.     movea.l    4,a6
  136.     CALLSYS    CloseLibrary
  137.  
  138. \@lib_not_opened$:
  139.  
  140.     ; Reply to workbench message if program was started from workbench
  141.  
  142.     tst.l    wb_msg
  143.     beq    \@skip_msg_reply$
  144.  
  145.     movea.l    4,a6
  146.     CALLSYS    Forbid
  147.  
  148.     movea.l    wb_msg,a1
  149.     CALLSYS    ReplyMsg
  150.  
  151. \@skip_msg_reply$:
  152.  
  153.     ; Set return code and exit
  154.  
  155.     move.l    d2,d0
  156.     rts
  157.  
  158.     endm
  159.  
  160.  
  161. ; Macro: GET_ADDRESS
  162. ; ==================
  163. ;
  164.  
  165.     macro    GET_ADDRESS
  166.  
  167.     ifne    $ff00&\1
  168.     ifne    $100&\1
  169. ADDRESS    set    $ff&\1
  170.     else
  171. ADDRESS    set    \1
  172.     endif
  173.     else
  174. ADDRESS    set    \1
  175.     endif
  176.  
  177.     endm
  178.  
  179.  
  180.     bss
  181.  
  182. wb_msg:            ds.l    1
  183. Atari2600Base:        ds.l    1
  184. environment:        ds.l    1
  185.  
  186. timed_out        ds.w    1
  187.  
  188.  
  189.     data
  190.  
  191. atari2600Name:
  192.  
  193.     dc.b    "atari2600.library",0
  194.  
  195.     cnop    0,4
  196.  
  197. extra_tags:
  198.  
  199.     dc.l    A2600TAG_WBMsg,0
  200.     dc.l    TAG_END
  201.  
  202.  
  203.     bss
  204.  
  205.     cnop    0,4
  206.  
  207. data:
  208.  
  209.     ds.b    $2000
  210.  
  211.  
  212.     endc
  213.  
  214.